﻿using UnityEngine;
using UnityEditor;

namespace TC
{
    public class StyleProvider
    {
        private static StyleCollection _styleCollection;

        public static StyleCollection StyleCollection
        {
            get { return _styleCollection ?? (_styleCollection = Resources.Load<StyleCollection>("StyleCollections/BluePrint")); }
        }

        public static GUIStyle NodeHeader { get => StyleCollection.NodeHeader; }

        public static GUIStyle NodeBackground { get => StyleCollection.NodeBackground; }

        public static GUIStyle NodeHighLight { get => StyleCollection.NodeHighLight; }

        public static GUIStyle ValuePortNormal { get => StyleCollection.ValuePortNormal; }

        public static GUIStyle ValuePortConnected { get => StyleCollection.ValuePortConnected; }

        public static GUIStyle FlowPortNormal { get => StyleCollection.FlowPortNormal; }

        public static GUIStyle FlowPortConnected { get => StyleCollection.FlowPortConnected; }

        public static GUIStyle PortGroupGizmos { get => StyleCollection.PortGroupGizmos; }

        public static GUIStyle PortGroupBG { get => StyleCollection.PortGroupBG; }

        public static GUIStyle PortDefaultValueBG { get => StyleCollection.PortDefaultValueBG; }

        public static Color DefaultConnectColor { get => StyleCollection.DefaultConnectColor; }

        public static Color ActiveConnectColor { get => StyleCollection.ActiveConnectColor; }

        public static GUIStyle MenuItemBg { get => StyleCollection.MenuItemBg; }

        public static GUIStyle MenuItemBtn { get => StyleCollection.MenuItemBtn; }

        public static GUIStyle MenuItemName { get => StyleCollection.MenuItemName; }

        public static Color CustomElementColor { get=> EditorGUIUtility.isProSkin? StyleCollection.ProfessionalFlowPortColor: StyleCollection.PersonalFlowPortColor; }

        public static Color GetVariableColor(System.Type type)
        {
            if (EditorGUIUtility.isProSkin)
            {
                if (type.IsAssignableFrom(typeof(FlowNode)))
                {
                    return StyleCollection.ProfessionalFlowPortColor;
                }
                switch (type.Name)
                {
                    case "Boolean": return StyleCollection.ProfessionalBoolPortColor;
                    case "Int32": return StyleCollection.ProfessionalIntPortColor;
                    case "Single": return StyleCollection.ProfessionalFloatPortColor;
                    case "Double": return StyleCollection.PersonalDoublePortColor;
                    case "Int64": return StyleCollection.ProfessionalLongPortColor;
                    case "Char": return StyleCollection.ProfessionalCharPortColor;
                    case "String": return StyleCollection.ProfessionalStringPortColor;
                    default: return StyleCollection.ProfessionalDefaultPortColor;
                }
            }
            else
            {
                if (type.IsAssignableFrom(typeof(FlowNode)))
                {
                    return StyleCollection.PersonalFlowPortColor;
                }
                switch (type.Name)
                {
                    case "Boolean": return StyleCollection.PersonalBoolPortColor;
                    case "Int32": return StyleCollection.PersonalIntPortColor;
                    case "Single": return StyleCollection.PersonalFloatPortColor;
                    case "Double": return StyleCollection.PersonalDoublePortColor;
                    case "Int64": return StyleCollection.PersonalLongPortColor;
                    case "Char": return StyleCollection.PersonalCharPortColor;
                    case "String": return StyleCollection.PersonalStringPortColor;
                    default: return StyleCollection.PersonalDefaultPortColor;
                }
            }
        }


        #region 纯自定义Style

        private static GUIStyle _separatorLineStyle;
        public static GUIStyle separatorLineStyle
        {
            get
            {
                if (_separatorLineStyle == default)
                {
                    _separatorLineStyle = new GUIStyle("box");
                    _separatorLineStyle.fixedHeight = 1f;
                    _separatorLineStyle.stretchWidth = true;
                    _separatorLineStyle.margin = new RectOffset(0, 0, 5, 5);
                }
                return _separatorLineStyle;
            }
        }

        #endregion
    }
}